<template>
  <div class="common-table">
    <el-table :data="tableData" height="90%" stripe v-loading="config.loading">
      <el-table-column label="序号" width="85" align='center'>
        <template slot-scope="scope">
          <span>{{ (config.page - 1) * 20 + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column align='center' show-overflow-tooltip v-for="item in tableLabel" :key="item.prop" :label="item.label" :width="item.width ? item.width : 125">
        <template slot-scope="scope">
          <span >{{ scope.row[item.prop] }}</span>
        </template>
      </el-table-column>
      <el-table-column align='center' label="操作" min-width="180">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page">
             <el-pagination 
                :page-sizes="[20, 100, 200, 300, 400]"
                background 
                layout="total, sizes, prev, pager, next,jumper" 
                :total="config.total" 
                @size-change="handleSizeChange" 
                @current-change="handleCurrentChange"
             >
             </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    tableData: Array,
    tableLabel: Array,
    config: Object
  },
  methods: {
    handleEdit(row) {
      this.$emit('edit', row)
    },
    handleDelete(row) {
      this.$emit('del', row)
    },
    handleSizeChange(val) {
      this.$emit('handleSizeChange',val)
    },
    handleCurrentChange() {
       this.$emit('handleCurrentChange',val)
    }
  }
}
</script>

<style lang="scss" scoped>
.common-table {
  height: calc(100% - 62px);
  background-color: #fff;
  position: relative;
  .page {
    padding-top: 10px;
    text-align: right;
  }
}
</style>
